package service

import (
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/go-kratos/kratos/v2/errors"
	v1 "go-admin/api/admin/articles/v1"
	"net/http"
)

type ActiveService struct {
}

func NewActiveService(router *gin.Engine)  {
	service := &ActiveService{}
	v1.RegisterBlogServiceHTTPServer(router,service)
}

func (s ActiveService) Middleware () []gin.HandlerFunc  {
	arr := []gin.HandlerFunc{}
	arr = append(arr, func(c *gin.Context) {
		fmt.Println(1111111)
	})
	return arr
}

func (s ActiveService) CreateArticle(ctx context.Context, article *v1.Article) (*v1.Article, error) {
	if article.AuthorId < 1 {
		return nil, errors.Errorf(http.StatusBadRequest, "cw", "author id must > 0")
	}
	return article, nil
}

func (s ActiveService) GetArticles(ctx context.Context, req *v1.GetArticlesReq) (*v1.GetArticlesResp, error) {
	if req.AuthorId < 0 {
		return nil, errors.Errorf(http.StatusBadRequest, "cw", "author id must > 0")
	}
	return &v1.GetArticlesResp{
		Total: 1,
		Articles: []*v1.Article{
			{
				Title:    "test article: " + req.Title,
				Content:  "test",
				AuthorId: 1,
			},
		},
	}, nil
}

